<template>
	<view>
		<view class="flex justify-between" style="line-height: 100rpx;font-size: 38rpx;padding: 0rpx 40rpx;">
			<view class="text-blue" v-if="order.state ==0">待付款</view>
			<view class="text-blue" v-if="order.state ==1">进行中</view>
			<view class="text-blue" v-if="order.state ==2">已完成</view>
			<view class="text-blue" v-if="order.state ==3" style="color: #999999;">已取消</view>
			<!-- <view style="color: #1E1F31;">{{order.updateTime}}</view> -->
		</view>
		<view class="padding-lr padding-bottom" v-if="order.name">
			<view class="bg padding radius" v-if="order.serviceMethod === '1'">
				<view class="flex">
					<view>
						<image src="../../static/images/place1.png"
							style="width: 80rpx;height: 80rpx;border-radius: 10upx;"></image>
					</view>
					<view class="text-white margin-left-sm" @click="undateAdd(order)">
						<view>{{order.name}}<text class="margin-left-sm">{{order.phone}}</text></view>
						<view class="margin-top-xs">{{order.city}}{{order.district}}{{order.detailsAddress}}</view>
					</view>
				</view>
			</view>
			<view class="bg padding radius margin-top">
				<view class=" u-flex " @click="binddetail(order)">
					<view class="u-m-r-10" v-if="order.orderTaking">
						<!-- <u-avatar :src="order.user.avatar" size="68"></u-avatar> -->
						<image :src="order.orderTaking.homepageImg"
							style="width: 140rpx;height: 140rpx;border-radius: 8upx;" mode="aspectFill"></image>
					</view>
					<view class="u-flex-1 text-white" v-if="order.orderTaking">
						<view class="u-font-14  text-bold padding-bottom-xs u-line-1" style="width: 480rpx;">
							{{order.orderTaking.myLevel}}
						</view>
						<view class="margin-top-xs margin-bottom-xs ">
							<text class="padding-xs text-lg ">{{order.orderNumber}}</text>{{order.orderTaking.unit}}
						</view>
						<view class="padding-top-xs text-lg">
							<text style="font-size: 20rpx;">￥</text>
							{{ order.orderTaking.oldMoney}}/{{order.orderTaking.unit}}<text
								style="font-size: 20rpx;margin-left: 10rpx;">*</text>
							<text
								style="color: #666666;margin-left: 10rpx;">{{order.orderNumber}}{{order.orderTaking.unit}}</text>
						</view>
					</view>
				</view>
				<view class="flex justify-between margin-top">
					<view style="width: 120upx;">实付款</view>
					<view class="text-white text-lg" v-if="order.paySumMoney">
						<text class="text-sm">￥</text>{{order.paySumMoney}}
					</view>
					<view class="text-white text-lg" v-else>
						<text class="text-sm">￥</text>{{order.payMoney}}
					</view>
				</view>
			</view>

			<view class="bg padding radius margin-top" v-if="order">
				<view class="text-lg text-bold">
					服务信息
				</view>
				<view class=" margin-right-xs">
					<view class="flex justify-between margin-top-lg" v-if="order.couponMoney">
						<view class="text-bold" style="width: 120upx;">优惠劵</view>
						<view>-{{order.couponMoney}}元</view>
					</view>
					<view class="flex justify-between margin-top-lg">
						<view class="text-bold" style="width: 120upx;">确认码</view>
						<view>{{order.code}}</view>
					</view>
					<view class="flex justify-between margin-top-lg" v-if="order.orderTaking">
						<view class="text-bold" style="width: 120upx;">服务类型</view>
						<view><text v-for="(item,index) in order.orderTaking.gameId" :key="index"
								class="margin-left-sm">{{item}}</text></view>
					</view>
					<view class="flex justify-between margin-top-lg">
						<view class="text-bold" style="width: 120upx;">预约时间</view>
						<view class="text-white">{{order.startTime}}</view>
					</view>
					<view class="flex justify-between margin-top-lg text-right" v-if="order.serviceMethod === '1'">
						<view class="text-bold" style="width: 120upx;text-align: left;">服务地点</view>
						<view class="text-white" style="width: 80%;"
							@tap="bindGps(order.latitude,order.longitude,order.detailsAddress)">
							{{order.city}}{{order.district}}{{order.detailsAddress}}
							<u-icon name="map"></u-icon>
						</view>
					</view>
					<view class="flex justify-between margin-top-lg" v-if="order.user && order.user.shopPhone">
						<view class="text-bold" style="width: 120upx;">联系方式</view>
						<view class="text-white" @click="bindphone(order.user.shopPhone)">
							{{order.user.shopPhone.substring(0, 3) + "****" + order.user.shopPhone.substring(7)}}
							<u-icon name="phone"></u-icon>
						</view>
					</view>
					<view class="flex justify-between margin-top-lg">
						<view class="text-bold" style="width: 120upx;">在线聊天</view>
						<view class="text-white" @click="goMsg">联系TA<u-icon name="chat"></u-icon>
						</view>
					</view>
					<view class=" margin-top-lg">
						<view class="text-bold" style="width: 165rpx;">备注</view>
						<view class="text-white margin-top">{{order.remarks?order.remarks:'暂无备注'}}</view>
					</view>
				</view>
				<!-- <view class="flex justify-between margin-top">
				<view @click="goMsg">
					<u-icon name="chat" size="32" color="#557EFD" class="margin-right-sm"></u-icon>联系TA
				</view>
				<view class="text-white">实付：<text class="text-lg text-bold">{{order.payMoney}}元</text></view>
			</view> -->
			</view>

			<view class="bg padding radius margin-top" v-if="order.state==1||order.state==2">
				<view class="text-lg text-bold margin-bottom">服务前照片</view>
				<view class="flex flex-wrap justify-between">
					<view class="flex margin-bottom-sm"
						style="width: 48%;height: 200rpx;margin-right: 5rpx;position: relative;"
						v-for="(image,index) in order.startServiceImg" :key="index"
						@click="saveImg( order.startServiceImg,index)">
						<image :src="image" style="width: 100%;height: 100%;border-radius: 10upx;" mode="aspectFill">
						</image>
					</view>
				</view>
			</view>
			<view class="bg padding radius margin-top" v-if="order.state==2">
				<view class="text-lg text-bold margin-bottom">服务后照片</view>
				<view class="flex flex-wrap justify-between">
					<view class="flex margin-bottom-sm"
						style="width: 48%;height: 200rpx;margin-right: 5rpx;position: relative;"
						v-for="(image,index) in order.endServiceImg" :key="index"
						@click="saveImg(order.endServiceImg,index)">
						<image :src="image" style="width: 100%;height: 100%;border-radius: 10upx;" mode="aspectFill">
						</image>
					</view>
				</view>
			</view>

			<view class="bg padding radius margin-top" style="margin-bottom: 140rpx;">
				<view class="text-lg text-bold">
					订单信息
				</view>
				<view class="margin-right-xs">
					<view class="flex justify-between margin-top-lg" v-if="order.refundSumMoney">
						<view class="text-bold" style="width: 140upx;">退款总金额 </view>
						<view  class="text-white">{{order.refundSumMoney}}元</view>
					</view>
					<view class="flex justify-between margin-top-lg" v-if="order.paySumMoney">
						<view class="text-bold" style="width: 140upx;">支付总金额 </view>
						<view  class="text-white">{{order.paySumMoney}}元</view>
					</view>
					
					<view class="flex justify-between margin-top-lg">
						<view class="text-bold" style="width: 120upx;">订单编号</view>
						<view @click="copyOrder(order.ordersNo)" class="text-white">{{order.ordersNo}}
							<u-icon name="order"></u-icon>
						</view>
					</view>
					<view class="flex justify-between margin-top-lg">
						<view class="text-bold" style="width: 120upx;">下单时间</view>
						<view class="text-white">{{order.createTime}}</view>
					</view>
					<!-- <view class="flex justify-between margin-top-lg">
						<view style="width: 120upx;">支付方式</view>
						<view class="text-white">{{order.createTime}}</view>
					</view> -->
				</view>
			</view>

			<view class="flex tabber padding-tb-sm  " v-if="order.state == 0||order.state == 1||order.state == 2">
				<u-button @click="cancelOrder(order)" shape="circle" class="margin-right-sm" :custom-style="customStyle"
					:hair-line="false" v-if="order.state == 0">取消订单
				</u-button>
				<u-button @click="showPay = true" class="margin-right-sm" shape="circle" :custom-style="customStyle2"
					:hair-line="false" v-if="order.state == 0">立即支付
				</u-button>

				<u-button v-if="order.state == 1" class="margin-right-sm" :custom-style="customStyle2" shape="circle"
					:plain="true" @click="cancel()">订单完成</u-button>
				<u-button v-if="order.state == 1" class="margin-right-sm"
					:custom-style="customStyle2" shape="circle" :plain="true" @click="openMoney">补费</u-button>
				<u-button v-if="order.state == 2" class="margin-right-sm" :custom-style="customStyle2" shape="circle"
					:plain="true" @click.stop="goNav('/my/order/complain?byUserId='+order.user.userId+'&platform=4')">
					去投诉</u-button>
			</view>

			<u-popup v-model="showMoney" mode="center" border-radius="14" :closeable="true" width="650" height="380rpx">
				<view class="padding-top" style="width: 100%;text-align: center;font-size:38rpx;font-weight: bold;">
					补费金额
				</view>
				<view class="margin-lr padding-lr margin-top-xl" style="background: #f5f5f5;margin-bottom: 50rpx;">
					<u-input v-model="money" placeholder="请输入补费金额" type="number" />
				</view>
				<view
					style="width: 600rpx;height: 80rpx;background:#557EFD;color:#FFFFFF;text-align: center;line-height: 80rpx;border-radius: 16rpx;margin: 30rpx;"
					@tap="openPay()">确认支付</view>
			</u-popup>

			<u-popup v-model="showPay" mode="bottom" border-radius="14" :closeable="true">
				<view
					style="width: 100%;text-align: center;font-size:38rpx;font-weight: bold;margin-top:15rpx;margin-bottom: 80rpx;">
					选择支付方式
				</view>
				<view style="display: flex;height: 100upx;align-items: center;padding: 20upx 30rpx;"
					v-for="(item,index) in openLists" :key='index'>
					<view style="display: flex;width:80%;align-items: center;">
						<image :src="item.image" style="width: 55upx;height: 55upx;border-radius: 50upx;"></image>
						<view style="font-size: 30upx;margin-left: 20upx;width: 70%;">{{item.text}}
						</view>
					</view>
					<view style="width: 20%;display: flex;justify-content: flex-end;">
						<radio-group name="openWay" style="margin-left: 20upx;" @tap='selectWay(item.id)'>
							<label class="tui-radio">
								<radio color="#1789FD" :checked="openWay === item.id ? true : false" />
							</label>
						</radio-group>
					</view>
				</view>
				<view
					style="width: 690rpx;height: 80rpx;background:#557EFD;color:#FFFFFF;text-align: center;line-height: 80rpx;border-radius: 50rpx;margin: 30rpx;"
					@tap="pay()">确认支付</view>
			</u-popup>
			<u-popup v-model="showPay1" mode="bottom" border-radius="14" :closeable="true">
				<view
					style="width: 100%;text-align: center;font-size:38rpx;font-weight: bold;margin-top:15rpx;margin-bottom: 80rpx;">
					选择支付方式
				</view>
				<view style="display: flex;height: 100upx;align-items: center;padding: 20upx 30rpx;"
					v-for="(item,index) in openLists" :key='index'>
					<view style="display: flex;width:80%;align-items: center;">
						<image :src="item.image" style="width: 55upx;height: 55upx;border-radius: 50upx;"></image>
						<view style="font-size: 30upx;margin-left: 20upx;width: 70%;">{{item.text}}
						</view>
					</view>
					<view style="width: 20%;display: flex;justify-content: flex-end;">
						<radio-group name="openWay" style="margin-left: 20upx;" @tap='selectWay(item.id)'>
							<label class="tui-radio">
								<radio color="#1789FD" :checked="openWay === item.id ? true : false" />
							</label>
						</radio-group>
					</view>
				</view>
				<view
					style="width: 690rpx;height: 80rpx;background:#557EFD;color:#FFFFFF;text-align: center;line-height: 80rpx;border-radius: 50rpx;margin: 30rpx;"
					@tap="pay1()">确认支付</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import {
		showToast
	} from '../../common/queue'
	export default {
		data() {
			return {
				customStyle: {
					width: "230upx",
					margin: "0rpx 30rpx 0rpx 0rpx",
				},
				customStyle2: {
					backgroundColor: '#557EFD',
					color: '#FFFFFF',
					width: "230upx",
					margin: "0rpx 30rpx 0rpx 0rpx",
				},
				id: '',
				order: {
					user: {},
					game: {}
				},
				isTrue: 0,

				phone: '',
				isVip: false,
				showPay: false,
				openWay: 0,
				openLists: [{
					image: '../../static/images/zhifubao.png',
					text: '支付宝',
					id: 1
				}, {
					image: '../../static/images/icon_weixin.png',
					text: '微信',
					id: 2
				}],
				showMoney: false,
				money: '',
				showPay1: false
			}
		},
		onLoad(e) {
			this.isTrue = e.isTrue
			uni.setNavigationBarTitle({
				title: '订单详情'
			})
			this.id = e.id

			// #ifdef APP-PLUS
			this.openLists = [{
				image: '../../static/images/zhifubao.png',
				text: '支付宝',
				id: 1
			}, {
				image: '../../static/images/icon_weixin.png',
				text: '微信',
				id: 2
			}, {
				image: '../../static/images/lingqian.png',
				text: '零钱',
				id: 3
			}];
			this.openWay = 1;
			// #endif

			// #ifdef MP-WEIXIN
			this.openLists = [{
				image: '../../static/images/icon_weixin.png',
				text: '微信',
				id: 2
			}, {
				image: '../../static/images/lingqian.png',
				text: '零钱',
				id: 3
			}];
			this.openWay = 2;
			// #endif

			// #ifdef H5
			this.openLists = [{
				image: '../../static/images/zhifubao.png',
				text: '支付宝',
				id: 1
			}, {
				image: '../../static/images/lingqian.png',
				text: '零钱',
				id: 3
			}];
			this.openWay = 1;
			// #endif
			// this.getOrder()
		},
		onShow() {
			this.getOrder()
			this.token = uni.getStorageSync('token')
			if (uni.getStorageSync('token')) {
				this.getIsVip()
			}
		},
		methods: {
			goNav(url) {
				uni.navigateTo({
					url
				})
			},
			copyOrder(order) {
				let that = this;
				uni.setClipboardData({
					data: order,
					success: function() {
						that.$queue.showToast('复制成功')
					}
				})
			},
			// 修改订单地址
			undateAdd(order) {
				if (order.state == 0) {
					uni.navigateTo({
						url: '../address/address?order=' + order.ordersId + '&id=' + 3
					})
				}
			},
			// 查看图片
			saveImg(imgs, index) {
				if (this.LBSelect) {
					if (index == this.LBIndex - 1) {
						return;
					}
				}
				// console.log(imgs)
				let that = this;
				let imgArr = imgs
				// imgArr.push(imgs);
				// //预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[index]
				});
			},
			// 一键导航
			bindGps(latitude, longitude, name) {
				uni.openLocation({
					latitude: latitude - 0, //要去的纬度-地址       
					longitude: longitude - 0, //要去的经度-地址
					name: name, //地址名称
					address: name, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error)
					}
				});
			},
			// 拨打电话
			bindphone(phone) {
				let that = this
				// uni.showModal({
				// 	title: '提示',
				// 	content: '是否拨打电话',
				// 	success: function(res) {
				// 		if (res.confirm) {
				// 			console.log('用户点击确定', that.phone);
				// 			uni.makePhoneCall({
				// 				phoneNumber: phone //仅为示例
				// 			});
				// 		} else if (res.cancel) {
				// 			console.log('用户点击取消');
				// 		}
				// 	}
				// });
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			binddetail(e) {
				console.log(e)
				uni.navigateTo({

					url: '/pages/index/game/order?id=' + e.orderTakingId
				})
			},
			getOrder() {
				let data = {
					id: this.id
				}
				this.$Request.get('/app/orders/queryOrders', data).then(res => {
					if (res.code == 0) {
						this.order = res.data
						if (this.order.startServiceImg) {
							this.order.startServiceImg = this.order.startServiceImg.split(',')
						}
						if (this.order.endServiceImg) {
							this.order.endServiceImg = this.order.endServiceImg.split(',')
						}
						if (this.order.orderTaking.gameId) {
							this.order.orderTaking.gameId = this.order.orderTaking.gameId.split(",");
						}
						// if (this.order.user && this.order.user.shopPhone) {
						// 	let mobie = this.order.user.shopPhone
						// 	this.order.user.shopPhone = mobie.substring(0, 3) + "****" + mobie.substring(
						// 		7)
						// }
						if (this.order.phone) {
							let mobie = this.order.phone
							this.order.mobie = mobie.substring(0, 3) + "****" + mobie.substring(
								7)
						}

						console.log(this.vipMoney, 'vipvipvipv')
					}
				})
			},
			delOrder(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除订单吗?',
					success: function(res) {
						if (res.confirm) {
							let data = {
								id: e.ordersId,
							}
							that.$Request.get('/app/orders/deleteOrder', data).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: "删除成功"
									})
									// that.mescroll.resetUpScroll()
									uni.navigateBack()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
						uni.setStorageSync('isVIP', res.data)
					}
				});
			},
			// 支付订单
			pay() {
				let that = this
				that.showPay = false
				uni.showModal({
					title: '付款提示',
					content: '确认支付' + that.order.payMoney + '元吗?',
					success: function(re) {
						if (re.confirm) {
							that.showPay = false;
							//classify  1app  2公众号 3小程序
							let classify = 1;
							if (that.openWay == 2) { //微信
								// #ifdef MP-WEIXIN
								that.$Request.post("/app/wxPay/wxPayOrder", {
									orderId: that.order.ordersId,
									classify: 3
								}).then(red => {
									if (red.code == 0) {
										uni.requestPayment({
											provider: 'wxpay',
											timeStamp: red.data.timestamp,
											nonceStr: red.data.noncestr,
											package: red.data.package,
											signType: red.data.signType,
											paySign: red.data.sign,
											success: function(redd) {
												uni.removeStorageSync('EditAddress')
												uni.showLoading({
													title: '支付成功'
												});
												uni.hideLoading();
												setTimeout(function() {
													// uni.navigateBack();
													that.getOrder()
												}, 1000)
											},
											fail: function(err) {
												uni.hideLoading();
												that.$queue.showToast(
													'支付失败');
											}
										});
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

								// #ifdef H5
								that.$Request.post("/app/wxPay/wxPayOrder", {
									orderId: that.order.ordersId,
									classify: 2
								}).then(red => {
									if (red.code == 0) {
										that.callPay(red);
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

								// #ifdef APP-PLUS
								that.$Request.post("/app/wxPay/wxPayOrder", {
									orderId: that.order.ordersId,
									classify: 1
								}).then(red => {
									if (red.code == 0) {
										console.log(JSON.stringify(red))
										that.setPayment('wxpay', JSON.stringify(red.data));
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

							} else if (that.openWay == 1) { //支付宝
								// #ifdef H5
								that.$Request.post("/app/aliPay/payOrder", {
									orderId: that.order.ordersId,
									classify: 2
								}).then(red => {
									if (red.code == 0) {
										const div = document.createElement('div')
										div.innerHTML = red.data //此处form就是后台返回接收到的数据
										document.body.appendChild(div)
										document.forms[0].submit()
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif
								// #ifdef APP-PLUS
								that.$Request.post("/app/aliPay/payOrder", {
									orderId: that.order.ordersId,
									classify: 1
								}).then(red => {
									if (red.code == 0) {
										that.setPayment('alipay', red.data);
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif
							} else if (that.openWay == 3) { //零钱
								that.$Request.post("/app/orders/payMoney", {
									ordersId: that.order.ordersId,
								}).then(res => {
									if (res.code == 0) {
										uni.showToast({
											title: '支付成功'
										})
										setTimeout(function() {
											// uni.navigateBack();
											that.getOrder()
										}, 1000)
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none'
										})
									}
								});
							}

						} else if (re.cancel) {
							console.log('用户点击取消');
						}
					}

				})

			},
			openMoney() {
				this.money = ''
				this.showMoney = true
			},
			openPay() {
				let that = this
				if (!that.money) {
					uni.showToast({
						title: '请输入补费金额',
						icon: 'none'
					})
					return
				}

				if (Number(that.money) <= 0) {
					uni.showToast({
						title: '补费金额不能小于0',
						icon: 'none'
					})
					return
				}
				that.showMoney = false
				that.showPay1 = true
			},
			// 支付补费
			pay1() {
				let that = this
				that.showPay1 = false
				uni.showModal({
					title: '付款提示',
					content: '确认支付' + that.money + '元吗?',
					success: function(re) {
						if (re.confirm) {
							//classify  1app  2公众号 3小程序
							let classify = 1;
							if (that.openWay == 2) { //微信
								// #ifdef MP-WEIXIN
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 3,
									money: that.money,
									orderType: 2
								}).then(red => {
									that.money = ''
									if (red.code == 0) {
										uni.requestPayment({
											provider: 'wxpay',
											timeStamp: red.data.timestamp,
											nonceStr: red.data.noncestr,
											package: red.data.package,
											signType: red.data.signType,
											paySign: red.data.sign,
											success: function(redd) {
												uni.removeStorageSync('EditAddress')
												uni.showLoading({
													title: '支付成功'
												});
												uni.hideLoading();
												
												setTimeout(function() {
													// uni.navigateBack();
													that.getOrder()
												}, 1000)
											},
											fail: function(err) {
												uni.hideLoading();
												that.$queue.showToast(
													'支付失败');
											}
										});
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

								// #ifdef H5
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 2,
									money: that.money,
									orderType: 2
								}).then(red => {
									that.money = ''
									if (red.code == 0) {
										that.callPay(red);
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

								// #ifdef APP-PLUS
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 1,
									money: that.money,
									orderType: 2
								}).then(red => {
									that.money = ''
									if (red.code == 0) {
										console.log(JSON.stringify(red))
										that.setPayment('wxpay', JSON.stringify(red.data));
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif

							} else if (that.openWay == 1) { //支付宝
								// #ifdef H5
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 5,
									money: that.money,
									orderType: 2
								}).then(red => {
									that.money = ''
									if (red.code == 0) {
										const div = document.createElement('div')
										div.innerHTML = red.data //此处form就是后台返回接收到的数据
										document.body.appendChild(div)
										document.forms[0].submit()
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif
								// #ifdef APP-PLUS
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 4,
									money: that.money,
									orderType: 2
								}).then(red => {
									that.money = ''
									if (red.code == 0) {
										that.setPayment('alipay', red.data);
									} else {
										uni.showToast({
											title: red.msg,
											icon: 'none'
										})
									}
								});
								// #endif
							} else if (that.openWay == 3) { //零钱
								that.$Request.post("/app/orders/repairFee", {
									ordersId: that.order.ordersId,
									payType: 0,
									money: that.money,
									orderType: 2
								}).then(res => {
									that.money = ''
									if (res.code == 0) {
										uni.showToast({
											title: '支付成功'
										})
										setTimeout(function() {
											// uni.navigateBack();
											that.getOrder()
										}, 1000)
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none'
										})
									}
								});
							}

						} else if (re.cancel) {
							console.log('用户点击取消');
						}
					}

				})

			},
			callPay: function(response) {
				if (typeof WeixinJSBridge === "undefined") {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
						document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
					}
				} else {
					this.onBridgeReady(response);
				}
			},
			onBridgeReady: function(response) {
				let that = this;
				if (!response.package) {
					return;
				}
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', {
						"appId": response.appid, //公众号名称，由商户传入
						"timeStamp": response.timestamp, //时间戳，自1970年以来的秒数
						"nonceStr": response.noncestr, //随机串
						"package": response.package,
						"signType": response.signType, //微信签名方式：
						"paySign": response.sign //微信签名
					},
					function(res) {
						if (res.err_msg === "get_brand_wcpay_request:ok") {
							// 使用以上方式判断前端返回,微信团队郑重提示：
							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
							uni.removeStorageSync('EditAddress')
							uni.showLoading({
								title: '支付成功'
							});
							uni.hideLoading();
							setTimeout(function() {
								// uni.navigateBack();
								that.getOrder()
							}, 1000)
						} else {
							uni.hideLoading();
						}
						WeixinJSBridge.log(response.err_msg);
					}
				);
			},
			selectWay: function(id) {
				this.openWay = id;
			},
			setPayment(name, order) {
				let that = this;
				uni.requestPayment({
					provider: name,
					orderInfo: order, //微信、支付宝订单数据
					success: function(res) {
						uni.removeStorageSync('EditAddress')
						uni.showLoading({
							title: '支付成功'
						});
						uni.hideLoading();
						setTimeout(function() {
							// uni.navigateBack();
							that.getOrder()
						}, 1000)
					},
					fail: function(err) {
						uni.hideLoading();
						console.log(12)
					}
				});
			},
			// 完成订单
			cancel(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '订单完成后款项将支付给服务方，确认完成订单吗?',
					success: function(res) {
						if (res.confirm) {
							let data = {
								id: that.id,
								status: '2'
							}
							that.$Request.get('/app/orders/cancelOrder', data).then(res => {
								if (res.code == 0) {
									uni.navigateBack()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 取消订单
			cancelOrder(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认取消订单吗?',
					success: function(rese) {
						if (rese.confirm) {
							let data = {
								id: e.ordersId,
								status: '3'
							}
							that.$Request.get('/app/orders/cancelOrder', data).then(res => {
								if (res.code == 0) {
									uni.showToast({
										title: '取消成功',
										icon: 'none'
									})
									setTimeout(function() {
										uni.navigateBack()
									}, 1000)
								} else {
									that.$queue.showToast(res.msg)
								}
							})
						}
					}
				})
			},
			goMsg() {
				let data = {
					userId: uni.getStorageSync('userId'),
					focusedUserId: this.order.user.userId,
					userType: 1
				}
				this.$Request.postJson('/app/chat/insertChatConversation ', data).then(res => {
					if (res.code == 0) {
						let id = this.order.user.userId == res.data.userId ? res.data.focusedUserId : this.order
							.user.userId
						uni.navigateTo({
							url: '/pages/msg/chat?chatConversationId=' + res.data.chatConversationId +
								'&byUserId=' + id + '&byNickName=' + this.order.user.userName
						})
					}
				})
			},
		}
	}
</script>

<style>
	page {
		background: #f7f7f7;
	}

	.bg {
		background: #FFFFFF;
	}

	.tabber {
		width: 100%;
		background: #ffffff;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		justify-content: flex-end;
		height: 127rpx;
		/* padding-right: 30rpx; */
	}
</style>